package com.chapter16;

public class EightQueens {

	int helper[];
	
	EightQueens(){
		
	}
	EightQueens(int n){
		helper=new int[n];
	}
	
	public boolean checkPosition(int pos, int index, int[] A){
		for(int j=0;j<index;j++){
			if(A[j]==pos ||(Math.abs(j-index)==Math.abs(pos-A[j])))
				return false;
		}
		return true;
	}
	
	public void printPositions(int n){
		int[] A=new int[n];
		printPositions(0,A);
	}
	
	public void printPositions(int index, int[] A){
		if(index==A.length){
			for(int j=0;j<A.length;j++)
				System.out.print(A[j]+" ");
			System.out.println();
			return;
		}
		for(int i=0;i<A.length;i++){
			if(checkPosition(i,index,A)){
				A[index]=i;
				printPositions(index+1,A);
			}
		}
		
	}
}
